1627A A. Not Shading codeforces solution in cpp
by ujjal roy
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,r,c,i,co,t;
cin>>t;
while(t--)
{
co=0;
int ans=100000;
int re=1000000;
string s;
cin>>n>>m;
cin>>r>>c;
for(i=0;i<n;i++)
{
cin>>s;
for(int j=0;j<m;j++)
{
if(s[j]=='B')
{
int row=r-1;
int col=c-1;
if(i==row&&j==col) ans=0;
else if(i==row||j==col) ans=1;
else
{
ans=2;
}
re=min(re,ans);
co++;
}
}
}
if(co==0) cout<<"-1"<<endl;
else cout<<re<<endl;
}
}
0 Comments